﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DotNetCore.CAP;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace CapDemo.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private readonly ICapPublisher _capBus;
        private readonly ILogger<TestController> _logger;

        public TestController(ICapPublisher capBus, ILogger<TestController> logger)
        {
            _capBus = capBus;
            _logger = logger;
        }

        [Route("~/test/push")]
        [HttpGet]
        public IActionResult Push()
        {
            var r = new Random().Next(0, 10000);

            var str = DateTime.Now.ToString() + "---------" + r;
            _capBus.Publish("capdemo.test.msg", str);
            _logger.LogInformation($"消息发送成功:{str}");
            return Ok();
        }
    }
}
